﻿
@{
    ViewData["Title"] = "BanchAprrove";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<div class="layui-container">

    <div class="layui-row">


       
    </div>
    <div class="layui-row">

        <table class="layui-hide" id="applist" lay-filter="appst"></table>




    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="bachApp">批量同意</button>
        <button class="layui-btn layui-btn-sm" lay-event="bachRej">批量拒绝</button>
    </div>
</script>

<script>
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#applist'
            , toolbar: '#toolbarDemo'
            , url: '/api/Approve/WaitApproveList'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增s
            , cols: [[
                { type: 'checkbox' }
                , { field: 'id', width: 80, title: '编号' }
                , { field: 'content', title: '内容', sort: true }
                , { field: 'type', width: 80, title: '类型' }
                  , { field: 'reson', width: 180, title: '原因' }

            ]]
            , totalRow: true
            , page: true
            , id: 'testReload'
            , limits: 10
            , text: '请选择相关部门'
            , loading: true

        });
        table.on('toolbar(appst)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'bachApp':

                    var checkStatus = table.checkStatus('testReload');
                    var data = checkStatus.data;
                    // layer.alert(JSON.stringify(data));
                    console.log(JSON.stringify(data));
                    console.log("批量同意");
                    var dt = new Array();

                    for (let i = 0; i < data.length; i++) {

                        console.log(data[i].id);
                        dt[i] = data[i].id;
                    }
                    $.ajax({
                        type: 'POST',
                        url: '/api/approve/agree',
                        data: {

                            lst: dt,
                        }, dataType: "json",
                        success: function (data) {
                            layer.msg(data.msg);
                            table.reload('testReload', {
  url:  '/api/Approve/WaitApproveList'

});
                        }, error: function () {
                            layer.msg("请求失败，请再次尝试，或者检查网络", { icon: 5, time: 2000 });

                        }




                    });

                    break;
                case 'bachRej':
                        var checkStatus = table.checkStatus('testReload');
                    var data = checkStatus.data;
                    console.log("批量拒绝");
                    var dt = new Array();

                    for (let i = 0; i < data.length; i++) {

                        console.log(data[i].id);
                        dt[i] = data[i].id;
                    }
                    $.ajax({
                        type: 'POST',
                        url: '/api/approve/disagree',
                        data: {

                            lst: dt,
                        }, dataType: "json",
                        success: function (data) {
                            layer.msg(data.msg);
                            table.reload('testReload', {
                        url:  '/api/Approve/WaitApproveList'

});

                        }, error: function () {
                            layer.msg("请求失败，请再次尝试，或者检查网络", { icon: 5, time: 2000 });

                        }




                    });

                    break;

            };


        });
            
        });


   
</script>


